<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>小练习3-JS进阶（二）</title>
    </head>
    <body class="cols">
        <pre>
            <code>
                    // 小练习3：根据函数是第一等公民的思维，如何优化下面的代码？

                    function getUser(path, callback) {
                        return $.get(path, function(info) {
                            return callback(info);
                        })
                    }

                    getUser('/api/user', function(resp) {
                        // resp为成功请求之后返回的数据
                        console.log(resp);
                    })
            </code>
        </pre>
        <pre>
            <code>
                    function getUser(path, callback) {
                        return $.get(path, callback);
                    }

                    getUser('/api/user', function(resp) {
                        // resp为成功请求之后返回的数据
                        console.log(resp);
                    })
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/p_3.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>
</html>